﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_14
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n, s = 1;
            try
            {
                n = int.Parse(textBox1.Text);
                for (int i = 1; i <= n; i++)
                {
                    checked
                    {
                        s *= i;
                    }
                }
                textBox2.Text = s.ToString();
            }
            catch (FormatException)
            {
                MessageBox.Show("输入格式不合法！");
                textBox1.Text = "";
                textBox1.Focus();
            }
            catch (OverflowException)
            {
                MessageBox.Show("溢出错误！");
                textBox1.Text = "";
                textBox1.Focus();
            }
            catch (Exception)
            {
                MessageBox.Show("其他异常！");
                textBox1.Text = "";
                textBox1.Focus();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }
    }
}